<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div{
        border:1px solid #ccc ;
        margin:10px;
        padding:10px;

      }
    </style>
  </head>
  <body>
    <div></div>
    <div></div>
    <div></div>
    <script src="../d3.js"></script>
    <script>
      const array = ['apple','orange','banana','mango','lemon'];

      // d3.select('body')
      //   .selectAll('div')
      //   .data(array)
      //   .text(d=>d)
      //   .enter()
      //   .append('div')
      //   .text(d=>d)

      // d3.select('body')
      //   .selectAll('div')
      //   .data(array)
      //   .join('div')
      //   .text(d=>d)
    
      d3.select('body')
        .selectAll('div')
        .data(array,(d,i)=>d?i+1:i)
        .join(
          (selection)=>{
            console.log('enter',selection);
            return selection.append('div').style('background','green');
          },
          (selection)=>{
            console.log('update',selection);
            return selection.style('background','red')
          },
          (selection)=>{
            console.log('exit',selection);
            return selection.style('background','blue')
          }
        )
        .text(d=>d)
    </script> 
  </body>
</html>
